home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Simulation / Dizzy 1.0+ source / menu.c < prev    next >
Text File  |  1990-12-28  |  2KB  |  109 lines

  1. /*
  2. >>    Dizzy 1.0 Menu.c
  3. >>
  4. >>    A digital circuit simulator & design program for the X Window System
  5. >>
  6. >>    Copyright 1990 Juri Munkki, all rights reserved
  7. */
  8.  
  9. #include "dizzy.h"
  10.  
  11. /*
  12. >>    DoMenuClick implements menu handling with just a few
  13. >>    graphics routines and a routine that uses events to
  14. >>    get the mouse state. It should be easy to port this
  15. >>    code to just about any platform.
  16. >>
  17. >>    Note that the user always has the choice of cancelling
  18. >>    an action before releasing the mouse button by moving
  19. >>    the mouse away from the menu area.
  20. >>
  21. >>    The same routine was used as a basis for the more
  22. >>    complicated tool selection routine.
  23. */
  24. void    DoMenuClick()
  25. {
  26.     Rect        HiliteRect,OldHiliteRect,Inside;
  27.     int         HiliteItem,NewHilite,i,downflag;
  28.     Point        MousePoint;
  29.     
  30. #ifdef    MACINTOSH
  31.     SetPort(MyWind);
  32. #endif
  33.     if(SplashVisible)
  34.     {    SplashVisible=0;
  35.         InvalTrash();
  36.     }
  37.  
  38.     Inside.left=MenuR.left+1;
  39.     Inside.right=MenuR.right-3;
  40.     Inside.top=MenuR.top+1;
  41.     Inside.bottom=MenuR.bottom-3;
  42.  
  43.     HiliteItem=0;
  44.     HiliteRect=Inside;
  45.     
  46.     do    /*    Track mouse while button is down.                */
  47.     {    downflag=GetMouseTrackEvent(&MousePoint);
  48.         if(PtInRect(MousePoint,&Inside))
  49.         {    /*    Find selected menu that mouse points to.    */
  50.             MousePoint.v-=Inside.top;
  51.             NewHilite=MousePoint.v/24;
  52.             HiliteRect.top=Inside.top+24*NewHilite;
  53.             HiliteRect.bottom=HiliteRect.top+24;
  54.             NewHilite++;
  55.         }
  56.         else
  57.         {    NewHilite=0;    /*    No selected item.            */
  58.         }
  59.         if(HiliteItem!=NewHilite)
  60.         {    if(HiliteItem)    /*    Unhilite old item.            */
  61.             {    HILITEMODE
  62.                 InvertRect(&OldHiliteRect);
  63.             }
  64.             if(NewHilite)    /*    Hilite new item.            */
  65.             {    HILITEMODE
  66.                 InvertRect(&HiliteRect);
  67.             }                /*    Old item = new item.        */
  68.             HiliteItem=NewHilite;
  69.             OldHiliteRect=HiliteRect;
  70.         }
  71.     }    while(downflag);    /*    Do until button comes up.    */
  72.  
  73.     if(HiliteItem)
  74.     {    for(i=MenuFlash*2;i;i--)    /*    Flash menu item.    */
  75.         {    long    dummy;
  76.         
  77.             HILITEMODE
  78.             InvertRect(&OldHiliteRect);
  79.             Delay(2,&dummy);
  80.         }
  81.         
  82.         MenuHilite=OldHiliteRect;
  83.     }
  84.     
  85.     switch(HiliteItem)            /*    Handle menu commands.    */
  86.     {    case 1: /*    Quit                                    */
  87.             QuitNow= -1;
  88.             break;
  89.         case 2: /*    Open…                                    */
  90.             PromptOpenFile();
  91.             break;
  92.         case 3: /*    Save                                    */
  93.             SaveFile();
  94.             break;
  95.         case 4: /*    Save as...                                */
  96.             SaveFileAs();
  97.             break;
  98.         case 5: /*    Include a custom chip                    */
  99.             AddCustomChip();
  100.             break;
  101.     }
  102.  
  103.     if(HiliteItem)            /*    Unhilite command, if any.    */
  104.     {    HILITEMODE;
  105.         InvertRect(&OldHiliteRect);
  106.     }
  107.     MenuHilite=NilRect;
  108. }
  109.